package com.west.imclient.listener;

import imserverentity.entity.IChattable;
import imserverentity.entity.Protocol;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;

import com.west.imclient.view.MeetingRoomView;

public class ShakeActionListener implements ActionListener{
	private MeetingRoomView meetingRoomView;
	private ObjectOutputStream oos;
	
	public ShakeActionListener(MeetingRoomView meetingRoomView, ObjectOutputStream oos) {
		this.meetingRoomView = meetingRoomView;
		this.oos = oos;
	}
	
	public void actionPerformed(ActionEvent e) {
		IChattable from = meetingRoomView.getClient();
		String to = null;
		if(meetingRoomView.getCjl().getSelectedIndex()!=-1) {
			to = (String) meetingRoomView.getCjl().getSelectedValue();
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("from", from);
		params.put("to", to);
		Protocol protocol = new Protocol("shake", params);
		System.out.println("Sender: " + protocol);

		try {
			oos.writeObject(protocol);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

}
